package com.sure0000.dataStructure;


/**
 * @program: demo
 * @description: 图 结构
 * @author: xuyouchang@supcon.com
 * @create: 2019-11-18 16:32
 **/
public class Graph {


    /**
     * 顶点数量
     */
    private Integer vertexSize;
    /**
     * 顶点数组
     */
    private Integer [] vertex;
    /**
     * 邻接矩阵
     */
    private Integer [] [] matrix;
    /**
     * 无穷大，代表不可达
     */
    private static final Integer MAX = 50;

    public Graph(Integer vertexSize) {
        this.vertexSize = vertexSize;
        matrix = new Integer[vertexSize][vertexSize];
        // 创建顶点数组,示例使用，最终定点数组的内容是0，1,2,3,4
        vertex=new Integer [vertexSize];
        for(int i=0;i<vertexSize;i++){
            vertex[i]=i;
        }
    }

    public Integer[] getVertex() {
        return vertex;
    }

    public void setVertex(Integer[] vertex) {
        this.vertex = vertex;
    }

    public static void main(String[] args) {
        Graph graph = new Graph(5);

        Integer [] a1=new Integer[]{0,MAX,MAX,MAX,6};
        Integer [] a2=new Integer[]{9,0,3,MAX,MAX};
        Integer [] a3=new Integer[]{2,MAX,0,5,MAX};
        Integer [] a4=new Integer[]{0,MAX,MAX,0,1};
        //创建5个一维数组
        Integer [] a5=new Integer[]{0,MAX,MAX,MAX,0};

        //将每行的数据赋值给图的邻接矩阵,邻接矩阵每行就是一个数组
        graph.matrix[0]=a1;
        graph.matrix[1]=a2;
        graph.matrix[2]=a3;
        graph.matrix[3]=a4;
        //到此邻接矩阵创建完成
        graph.matrix[4]=a5;

    }
}
